package com.wangyi.im.remoting;

import com.alibaba.fastjson.JSONObject;
import com.wangyi.im.execute.IMFriendExecute;
import com.wangyi.im.execute.IMUserExecute;
import com.wangyi.im.request.IMFriendAddRequest;
import com.wangyi.im.request.IMFriendGetRequest;
import com.wangyi.im.request.IMUserRequest;
import com.wangyi.im.request.IMUsersRequest;
import com.wangyi.im.response.IMFriendGetResponse;
import com.wangyi.im.response.IMResponse;
import com.wangyi.im.response.IMUserResponse;
import com.wangyi.im.utils.BuildDataUtil;
import retrofit2.Call;
import retrofit2.Response;

import java.io.IOException;
import java.util.List;

import static com.wangyi.im.constants.CommonConstants.FRIENDS;

public class IMFriendRemoting extends Remoting {

    public IMFriendRemoting(String baseUrl, String appKey, String appSecret) {
        super(baseUrl, appKey, appSecret);
    }

    public IMResponse<Boolean> addFriend(IMFriendAddRequest imFriendAddRequest){
        Call<JSONObject> call = getRetrofit(imFriendAddRequest).create(IMFriendExecute.class).addFriend();
        Response<JSONObject> retrofitResponse = null;
        try {
            retrofitResponse = call.execute();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new BuildDataUtil().buildData(retrofitResponse, Boolean.class, null);
    }

    public IMResponse<List<IMFriendGetResponse>> getFriend(IMFriendGetRequest imFriendGetRequest){
        Call<JSONObject> call = getRetrofit(imFriendGetRequest).create(IMFriendExecute.class).getFriend();
        Response<JSONObject> retrofitResponse = null;
        try {
            retrofitResponse = call.execute();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new BuildDataUtil().buildListData(retrofitResponse, IMFriendGetResponse.class, FRIENDS);
    }


}
